package com.module.content.ui.info.adapter

import android.widget.FrameLayout
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.allen.app.data.bean.InfoBean
import com.allen.app.data.bean.ProviderBean
import com.allen.base.base.basic.extras.load
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.content.R
import com.module.content.helper.ImageCalculateHelper

/**
 * author : Allen
 * date   : 2020/08/14
 * time   : 13:41
 * desc   : 糗事 图片适配器
 */
class InfoImageAdapter : InfoBaseAdapter() {

    override val itemViewType: Int = ProviderBean.PROVIDER_INFO_IMAGE

    override fun getContentView(): Int = R.layout.info_adapter_info_image

    override fun convertChild(helper: BaseViewHolder, adapterPosition: Int, item: InfoBean) {
        //单张图片显示
        val ivCover = helper.getView<ImageView>(R.id.ivCover)
        val imageSize = ImageCalculateHelper.getImageSize(item.image_size?.m)
        //按比例缩放，动态修改图片大小
        val params = ivCover.layoutParams
        if (params is FrameLayout.LayoutParams && imageSize != null) {
            params.width = imageSize.width
            params.height = imageSize.height
        }
        ivCover.load(item.high_url, 4f)
    }
}